<template>
  <div class="container">
    <el-dialog title="题目预览" :visible="showQPDialog" width="60%" @close="close">
      <el-row :gutter="20" style="margin-bottom: 20px">
        <el-col :span="6">
          【题型】:
          {{ formatQuestionType(tableList.questionType) }}</el-col>
        <el-col :span="6"> 【编号】: {{ tableList.id }}</el-col>
        <el-col :span="6">
          【难度】: {{ formatDifficulty(tableList.difficulty) }}</el-col>
        <el-col :span="6"> 【标签】: {{ tableList.tags }}</el-col>
      </el-row>
      <el-row :gutter="20" style="margin-bottom: 20px">
        <el-col :span="6">【学科】:{{ list.subject }}</el-col>
        <el-col :span="6">【目录】:{{ tableList.catalogID }}</el-col>
        <el-col :span="6">【方向】:{{ tableList.direction }}</el-col>
      </el-row>
      <el-divider></el-divider>
      <slot></slot>
      <el-divider></el-divider>
      <el-row>
        【参考答案】:
        <el-button type="danger" @click="playVideo">视频答案预览</el-button>
      </el-row>
      <el-row>
        <video v-if="showVideo === true" :src="tableList.videoURL" width="300px" controls="controls" height="150px"></video>
      </el-row>
      <el-divider></el-divider>
      <el-row>
        【答案解析】:
        <div v-html="tableList.answer"></div>
      </el-row>
      <el-divider></el-divider>
      <el-row>
        【题目备注】:
        {{ tableList.remarks }}
      </el-row>
      <span slot="footer" class="dialog-footer" style="text-align: right">
        <el-button type="primary" @click="$emit('update:showQPDialog')">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    showQPDialog: {
      type: Boolean,
      default: false
    },
    tableList: {
      type: Object,
      default: () => ({})
    },
    list: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      showVideo: false
    }
  },
  methods: {
    close () {
      this.$emit('update:showQPDialog')
      this.showVideo = false
    },
    // 根据映射关系转换题型、难度、状态
    formatDifficulty (difficulty) {
      const difficultyMap = {
        1: '简单',
        2: '一般',
        3: '困难'
      }
      return difficultyMap[difficulty]
    },
    formatQuestionType (questionType) {
      const questionTypeMap = {
        1: '单选',
        2: '多选',
        3: '简答'
      }
      return questionTypeMap[questionType]
    },
    playVideo () {
      this.showVideo = true
    }
  }
}
</script>

<style scoped lang='scss'>
::v-deep .el-dialog__footer {
  text-align: right;
}
</style>
